package org.ucas.faker.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import org.ucas.faker.web.entity.User;

/**
 * Created by suemi on 17-7-2.
 */
@Controller
public class RouteController extends BaseController {

  @RequestMapping(value = "/", method = RequestMethod.GET)
  public ModelAndView home() {
    User user = currentUser();
    if(user == null) {
      user = userService.findByAccount("root");
      context().userId = user.getId();
    }
    ModelAndView view = new ModelAndView("/user/login");
    if(currentUserId() != null)
      view.addObject("user",user);

    return view;
  }


  @RequestMapping(value = "/sewin.html",method = RequestMethod.GET)
  public ModelAndView seWindow() {
    User user = currentUser();
    if(user == null) {
      user = userService.findByAccount("root");
      context().userId = user.getId();
    }
    ModelAndView view = new ModelAndView("sewin");
    if(currentUserId() != null)
      view.addObject("user",user);

    return view;
  }
  
 
  
  
  @RequestMapping(value = "/searchwin.html",method = RequestMethod.GET)
  public ModelAndView searchWindow() {
	    User user = currentUser();
	    if(user == null) {
	      user = userService.findByAccount("root");
	      context().userId = user.getId();
	    }
	    ModelAndView view = new ModelAndView("searchwin");
	    if(currentUserId() != null)
	      view.addObject("user",user);

	    return view;
	  }
  
  
  @RequestMapping(value = "/showwin.html",method = RequestMethod.GET)
  public ModelAndView showWindow() {
	    User user = currentUser();
	    if(user == null) {
	      user = userService.findByAccount("root");
	      context().userId = user.getId();
	    }
	    ModelAndView view = new ModelAndView("showwin");
	    if(currentUserId() != null)
	      view.addObject("user",user);

	    return view;
	  }
  
  
  @RequestMapping(value = "/showtewin.html",method = RequestMethod.GET)
  public ModelAndView showTechEffWindow() {
	    User user = currentUser();
	    if(user == null) {
	      user = userService.findByAccount("root");
	      context().userId = user.getId();
	    }
	    ModelAndView view = new ModelAndView("showtewin");
	    if(currentUserId() != null)
	      view.addObject("user",user);

	    return view;
	  }
  
  @RequestMapping(value = "/report/report.html",method = RequestMethod.GET)
  public ModelAndView analysis() {
    User user = currentUser();
    if(user == null) {
      user = userService.findByAccount("root");
      context().userId = user.getId();
    }
    ModelAndView view = new ModelAndView("/report/report");
    if(currentUserId() != null)
      view.addObject("user",user);

    return view;
  }
  @RequestMapping(value = "/graph/statistical.html",method = RequestMethod.GET)
  public ModelAndView graphshow() {
	  User user = currentUser();
	  if(user == null) {
	    user = userService.findByAccount("root");
	    context().userId = user.getId();
	  }
	  ModelAndView view = new ModelAndView("/graph/statistical");
	  if(currentUserId() != null)
	    view.addObject("user",user);
	  return view;
  }
  
  @RequestMapping(value = "/patents/similarpatentslist.html",method = RequestMethod.GET)
  public ModelAndView similarpatentslist() {
	  User user = currentUser();
	  if(user == null) {
	    user = userService.findByAccount("root");
	    context().userId = user.getId();
	  }
	  ModelAndView view = new ModelAndView("/patents/similarpatentslist");
	  if(currentUserId() != null)
	    view.addObject("user",user);
	  return view;
  }
  @RequestMapping(value = "/graph/deep.html",method = RequestMethod.GET)
  public ModelAndView graphdeep() {
	  User user = currentUser();
	  if(user == null) {
	    user = userService.findByAccount("root");
	    context().userId = user.getId();
	  }
	  ModelAndView view = new ModelAndView("/graph/deep");
	  if(currentUserId() != null)
	    view.addObject("user",user);
	  return view;
  }
  @RequestMapping(value = "/graph/configure.html",method = RequestMethod.GET)
  public ModelAndView configure() {
	  User user = currentUser();
	  if(user == null) {
	    user = userService.findByAccount("root");
	    context().userId = user.getId();
	  }
	  ModelAndView view = new ModelAndView("/graph/configure");
	  if(currentUserId() != null)
	    view.addObject("user",user);
	  return view;
  }
  @RequestMapping(value = "/graph/showtewin.html",method = RequestMethod.GET)
  public ModelAndView showtewin() {
	  User user = currentUser();
	  if(user == null) {
	    user = userService.findByAccount("root");
	    context().userId = user.getId();
	  }
	  ModelAndView view = new ModelAndView("/graph/showtewin");
	  if(currentUserId() != null)
	    view.addObject("user",user);
	  return view;
  }
  @RequestMapping(value = "/filter.html",method = RequestMethod.GET)
  public ModelAndView filter() {
	  User user = currentUser();
	  if(user == null) {
	    user = userService.findByAccount("root");
	    context().userId = user.getId();
	  }
	  ModelAndView view = new ModelAndView("filter");
	  if(currentUserId() != null)
	    view.addObject("user",user);
	  return view;
  }
  
  @RequestMapping(value = "/spkey.html",method = RequestMethod.GET)
  public ModelAndView showSpecialKeywordWindow() {
	    User user = currentUser();
	    if(user == null) {
	      user = userService.findByAccount("root");
	      context().userId = user.getId();
	    }
	    ModelAndView view = new ModelAndView("spkey");
	    if(currentUserId() != null)
	      view.addObject("user",user);

	    return view;
	  }
  
  @RequestMapping(value = "/historys/searchhistory.html",method = RequestMethod.GET)
  public ModelAndView searchHistory() {
	    User user = currentUser();
	    if(user == null) {
	      user = userService.findByAccount("root");
	      context().userId = user.getId();
	    }
	    ModelAndView view = new ModelAndView("/historys/searchhistory");
	    if(currentUserId() != null)
	      view.addObject("user",user);

	    return view;
	  }
  @RequestMapping(value = "/tools/keywordtools.html",method = RequestMethod.GET)
  public ModelAndView keywordtools() {
	    User user = currentUser();
	    if(user == null) {
	      user = userService.findByAccount("root");
	      context().userId = user.getId();
	    }
	    ModelAndView view = new ModelAndView("/tools/keywordtools");
	    if(currentUserId() != null)
	      view.addObject("user",user);

	    return view;
	  }
}
